package com.ocom.payconfig.interceptor;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.ocom.common.utils.CommonUtil;
import com.ocom.security.authentication.YoCiUser;
import com.ocom.security.utils.SecurityUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author zhuhui
 * @Date 2023年9月28日16:58:20
 * @Description
 */
public class ScopeUpdateWrapper<T> extends UpdateWrapper<T> {

    public ScopeUpdateWrapper() {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        String token = request.getHeader("Authorization");
        if(!CommonUtil.isNull(token)){
            YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
            if(yoCiUser.getRole()==21l){
                super.eq(" com_id",yoCiUser.getComId());
            }
            if(yoCiUser.getRole()==41l || yoCiUser.getRole()==42l || yoCiUser.getMerchId()>0l){
                List<Long> merchId= yoCiUser.getWxAdmin();
                if(merchId.size()>0){
                    super.in("merch_id",merchId);
                }
            }
        }
    }

}